const express = require("express");
const cors = require("cors");
const app = express();
const PORT = 3001;
app.listen(PORT, () => {
  console.log(`app is listening on port ${PORT}`);
  console.log(new Date().toLocaleString());
});

//路由
const code_router = require("./routers/code_router");
const lots_router = require("./routers/query_lots");
const payquery_router = require("./routers/query_pay");
const query_vip = require("./routers/query_vip");
const query_price = require("./routers/query_price");
const user = require("./routers/users");
const verify_pwd = require("./routers/verify_pwd");

//跨域
app.use(cors());

//中间件
app.use(
  express.urlencoded({
    extended: true,
  })
);

//路由
app.use("/v1", code_router); //验证码
app.use("/v1", lots_router); //车位列表
app.use("/v1", payquery_router); //缴费查询
app.use("/v1", query_vip); //vip信息
app.use("/v1", user); //登录信息
app.use("/v1", query_price); //价格信息
app.use("/v1", verify_pwd); //二级密码验证

//错误处理中间件
//处理Mysql错误
app.use((err, req, res, next) => {
  console.log(err);
  res.send({ code: 500, msg: "Server Brake!" });
});
